package view.drawing;

import java.util.HashMap;
import java.util.Map;

/**
 * DrawManager is the main Singleton that controls all the currently
 * registered SpriteSheetSets with their associated ModelObject
 * instance.
 * 
 * @deviation
 * Included some convenience operations to be able to directly
 * get the SpriteSheet given the model name and its state
 * rather than make it a two-part operation.
 * 
 * @author matt
 *
 */
public class DrawManager {
	
	private Map<String, SpriteSheetSet> mModelSheets;
	
	private static DrawManager mInstance;
	
	static {
		mInstance = new DrawManager();
	}
	
	private DrawManager() {
		mModelSheets = new HashMap<String, SpriteSheetSet>();
	}
	
	public SpriteSheetSet getSpriteSheetSet(String modelName) {
		return (mModelSheets.get(modelName));
	}
	
	public boolean addSpriteSheetSet(String modelName, SpriteSheetSet set) {
		return (mModelSheets.put(modelName, set) != null);
	}
	
	public SpriteSheetSet removeSpriteSheetSet(String modelName) {
		return (mModelSheets.remove(modelName));
	}
	
	public static DrawManager getInstance() {
		return (mInstance);
	}
	
	/**
	 * Convenience operation to obtain a SpriteSheet given a model name
	 * and its associated state.
	 * 
	 * @param modelName
	 * @param state
	 * @return
	 */
	public SpriteSheet getSpriteSheet(String modelName, String state) {
		SpriteSheetSet set = this.getSpriteSheetSet(modelName);
		
		if (set == null) return (null);
		
		return (set.getSpriteSheet(state));
	}

}
